<?php
include_once '/var/www/html/new/d/common/header.html';
include_once '/var/www/html/new/d/common/left.html';
include_once '/var/www/html/new/d/class/Member.php';
include_once '/var/www/html/new/d/class/abc/Product.class.php';
include_once '/var/www/html/new/d/class/abc/Member.class.php';
include_once '/var/www/html/new/d/common/area.inc.php';


$ac = $GLOBALS['_ac'];
$pw = $GLOBALS['_pw'];
$s  = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true"));


$memberSID = $_SESSION['sid'];
$m         = new Member($s, $memberSID);
$salePros  = $m->salePros();




$list = array();
foreach($salePros as $k=>$data){
	$key = $data['lid'].'_'.$data['sapply_did'];
	$list[$key]['tickets'][] = array(
		'ttitle'=> $data['ttitle'],
		'pid' => $data['pid'],
		'tid' => $data['tid'],
		'tprice' => $data['tprice'],
		'sapply_did' => $data['sapply_did'],
		'lid' => $data['lid'],
	);
	if(!isset($list[$key]['ltitle'])){
		$list[$key]['ltitle']=$data['title'];
		$list[$key]['lid']=$data['lid'];
		$list[$key]['sapply_did']=$data['sapply_did'];
        $list[$key]['area'] = $data['area'];
	}
}
$r = $list;




// 获取绑定信息
$bind_a = array();
$sql = "select supplierIdentity,signkey,cooperation_way,DockingMode from uu_qunar_use where fid=$memberSID and DockingMode=0 limit 1";
$GLOBALS['le']->query($sql);
$GLOBALS['le']->fetch_assoc();
$supplierIdentity = $GLOBALS['le']->f('supplierIdentity');
$signkey = $GLOBALS['le']->f('signkey');
$cooperation_way = $GLOBALS['le']->f('cooperation_way');


$search_tidaid = "select id,tid_aid from uu_qunar_use where fid =".$memberSID;
$GLOBALS['le']->query($search_tidaid);	
$tidaid_data = array();
while($row=$GLOBALS['le']->fetch_assoc()){ 
	$tidaid_data[$row['id']] = $row['tid_aid']; 
}
// print_r($tidaid_data);
$boxHtml = '';

$selectTxt='<option>--------请选择---------</option>';
// print_r($list);

$today = date('Y-m-d');
foreach($list as $k=>$data){
    $ticketsHTML='';
    $bindCount = 0 ;
    foreach($data['tickets'] as $ticket){
		
		$pStorage = abc777\Product::Price($s, $ticket['pid'], $ticket['sapply_did'], $today);
		if($pStorage['js']==-1) continue;

		$ticket['msprice'] = $ticket['tprice'];
        $ticket['uprice']  = $pStorage['ls'];
        $ticket['jsprice'] = $pStorage['js'];

        $tidaid_value = $ticket['tid']."_".$memberSID;
        $checked = '';
        if(in_array($tidaid_value, $tidaid_data)){
            $checked = '已绑定';
			$del = '<div class="del">'.'<a href="###" class="remove" data="'.$tidaid_value.'">删除</a>'.'</div>';
            $bindCount = $bindCount + 1;
        }
        $ticketsHTML.=getHtml($ticket,$data,$tidaid_data,$memberSID,$tidaid_value,$checked,$del);
    }
	
    $boxHtml.= getBoxHtml(($data['lid']+$data['sapply_did']),$ticketsHTML);
    $areaArr = explode('|',$data['area']);
    if(count($data['tickets'])==$bindCount){
        $selectTxt.='<option value="'.($data['lid']+$data['sapply_did']).'">【已绑定】'.'['.$areas[$areaArr[0]].' '.$areas[$areaArr[1]].']'.$data['ltitle'].'</option>';
    }else{
        $selectTxt.='<option value="'.($data['lid']+$data['sapply_did']).'">['.$areas[$areaArr[0]].' '.$areas[$areaArr[1]].']'.$data['ltitle'].'</option>';
    }
    
}


// echo $boxHtml;

function getHtml($ticket,$row,$tidaid_data,$did,$tidaid_value,$checked,$del){
    		// print_r($ticket);
    $jsprice = $ticket['uprice'];
    return <<<h
<dl class="ticket" >
    <dt class="id" title="门票ID_上级供应商ID" data-title="供应商ID|景区ID|门票ID" data-a="{$ticket['sapply_did']}|{$ticket['lid']}|{$ticket['tid']}">
    {$ticket['tid']}_$did
    </dt>
    <dt class="title">
        <span title="{$row['ltitle']}">{$row['ltitle']}</span>
    </dt>
    <dd class="paymethod"><span title="{$ticket['ttitle']}">{$ticket['ttitle']}</span></dd>
    <dd class="price tprice">
        <i class="dollar">￥</i>{$ticket['msprice']}
    </dd>
    <dd class="price lprice">
        <i class="dollar">￥</i>{$ticket['tprice']}
    </dd>
    <dd class="price"><strong><i class="dollar">￥</i>
        $jsprice
       
        </strong>
    </dd>	
	<dd class="price"><strong>
        <ul class="tpl_variables">   
            <li>
            <a href="javascript:" class="var" data-code="{pname}" data-txt="<?=empty({$ticket['sapply_did']})? $memberID:{$ticket['sapply_did']},'|',{$row['pid']}?>
            {$row['ltitle']} &nbsp{$ticket['ttitle']}">
            <input name="ids[]" type="checkbox"  value="{$ticket['tid']}_$did" />$checked</a>
            {$del}
            </li>
        </ul>   
        </strong>
    </dd>	
</dl>
h;
}
function getBoxHtml($lid,$ticketsHTML){
    return <<<h
<div class="box" data="$lid" style="display:none;">
    <dl class="header">
        <dt class="id">供应商产品ID</dt>
        <dt class="title">景区</dt>
        <dd class="paymethod">门票类型</dd>
        <dd class="price">门市价</dd>
        <dd class="price">建议零售价</dd>
        <dd class="price">结算价</dd>
        <dd class="paymethod">选择</dd>	
    </dl>
    $ticketsHTML
</div>
h;
}
?>
<link rel="stylesheet" href="http://www.12301.cc/css/page.css" media="all" />
<script src="http://www.12301.cc/js/select2.js"></script>
<!-- <script src="http://apps.bdimg.com/libs/select2/3.4.8/select2.js"></script> -->
<!--<link rel="stylesheet" type="text/css" href="http://apps.bdimg.com/libs/select2/3.4.8/select2.css">-->
<link rel="stylesheet" type="text/css" href="http://www.12301.cc/css/select2.css">
<!-- <script type="text/javascript" src="js/qunaer_p.js"></script> -->

<div class="r_content" id="bind_tao">
    <h3 class="mc_title">
	  <!--   <span class="mctit_1 notcur"><a href="soap.html"><span class="mctit_2">回调地址</span></a></span> -->
        <span class="mctit_1"><span class="mctit_2">去哪儿配置</span></span>
    </h3>
	<div class="qunaertong">
		<!--<iframe name="ifr" style="display:none;"></iframe>-->
		<form action="call/qunaer.php" method="post" name="form">
			<p>
				<b class="tit">团购商家：</b>
                <!-- <span class="con1"> -->
                    <select name="DockingMode" id="bindselect" class="selectcss">
                        <option value="0">去哪儿</option>
						<option value="1">美团</option>
                    </select>
                <!-- </span> -->
			</p>
			<p>
				<b class="tit">供应商通信标识：</b>
				<span class="con1"><input type="text" class="inpcon" value="<?echo $supplierIdentity ? $supplierIdentity:"" ?>" id="ch_ops" name="Identity" <?if($supplierIdentity) echo 'readonly="readonly"'?>/></span>
                <b class="tit">（由团购商家提供）</b>
            </p>
			<p>
				<b class="tit">交互密钥：</b>
				<span class="con1"><input type="text" class="inpcon" value="<?echo $signkey ? $signkey:"" ?>" name="sign" onkeyup="chPs(this);" id="ch_nps" <?if($signkey) echo 'readonly="readonly"'?>/></span>
                <b class="tit">（由团购商家提供）</b>
            </p>

            <p class="setdisplay">
                <b class="tit">合作方式：</b>
                <!-- <span class="con1"> -->
                    <select name="cooperation_way" id="bindLista" class="selectcss">
                        <option
                            value="0" <?= $cooperation_way == 0 ? 'selected' : '' ?>>
                            佣金方式
                        </option>
                        <option
                            value="1" <?= $cooperation_way == 1 ? 'selected' : '' ?>>
                            底价方式
                        </option>
                    </select>
                <!-- </span> -->
                <b class="tit1">（默认为佣金方式。一个商家只能有一种合作方式）</b>
            </p>
			<p>
				<b class="tit">请选择产品：</b>
				<!-- <div class="jingqu"> 
					<span>请选择产品：</span>-->
					<!-- <span class="con1"> -->
						<select name="prodname" id="bindList" class="selectcss" >
						<?=$selectTxt?>
						</select>
					<!-- </span> -->
				<!-- </div> -->
			</p>
			</br>
			<script>
			$(function() {  
				$("#bindList").select2({
					placeholder: "Select a State",
					allowClear: true
				});
				$("#bindLista").select2({
					placeholder: "Select a State",
					allowClear: true
				});
				$("#bindselect").select2({
					placeholder: "Select a State",
					allowClear: true
				});
			
			$("#bindselect").change(function () {
		
				var i=$("#bindselect").val();
				$(".ticket").each(function(){
					var title_a = $(this).find(".id").attr("data-title");
					var value_a = $(this).find(".id").attr("data-a");
					var title_b = $(this).find(".id").attr("title");
					var value_b = $(this).find(".id").html();
					$(this).find(".id").attr("title",title_a).text(value_a).attr("data-title", title_b).attr("data-a", value_b);
				})
				
				if(i==0) $(".setdisplay").css("display","inline-block");
				if(i==1) $(".setdisplay").css("display","none");
				
			});
					
					
				
					
					
					//alert(b_title);
		
				
			});
			</script>
			<div class="clay1">
				<div class="content">
					<div class="boxs">
						<!--style="display:none;"-->
						<?=$boxHtml;?>
					</div>			
				</div>
			</div>
			<p><input type="submit" class="ok"  value="提交" /></p>
		</form>
	</div> 
</div>
<script type="text/javascript">
$(document).ready(function(){
	// $(".box").hide();

	$("#bindList").change(function(){
		_val=$(this).val();
		$(".box").hide();
		$(".box").each(function(i,ele){
			if($(ele).attr("data")==_val)
				$(ele).show();
		});
	});
    $(".remove").click(function(){
        if(confirm("您真的确定要删除吗？")==false) return false;
        var id = $(this).attr("data");
        $.ajax({
            "type":'POST',
            "url":"call/qunaer.php",
            "data":{"ac":"remove","id":id},
            "dataType":"json",
            "async":false,
            "success":function(out){
                if(out.status=="ok"){
                   window.location.reload(); 
                }else{
                    alert(out.msg);
                }
            }
        });
    
    });
	
});



</script>
<?
include 'common/footer.html';
?>